package org.example.aienglishapp.service.word;


import jakarta.annotation.PostConstruct;
import org.example.aienglishapp.entity.word.Word;
import org.example.aienglishapp.mapper.word.WordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;


import java.util.*;

@Service
public class WordService {

    @Autowired
    private WordMapper wordMapper;
    @Autowired
    private final JdbcTemplate jdbcTemplate;

    // 构造器注入 JdbcTemplate
    @Autowired
    public WordService(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public List<Word> getWordsByWordBook(String wordBook) {

        return wordMapper.findWordsByWordBook(wordBook);
    }

    public List<Word> getAllWords() {
        return wordMapper.getAllWords();
    }

    public Optional<Word> getWordWithExplanation(String word) {
        Optional<Word> result = wordMapper.getWordWithExplanation(word);
        System.out.println("Query Result: " + result); // 打印调试信息
        return result;
    }

    public String getChineseMeaning(String word) {
        return wordMapper.getChineseMeaning(word);
    }

    //新

    public ResponseEntity<?> getRandomWordFromBook(String book) {
        return null;
    }

    public ResponseEntity<?> addWordToWrongWords(String word, String book) {
        return null;
    }


    public List<Word> getWordsByDifficulty(String difficulty) {
        return wordMapper.getWordsByDifficulty(difficulty);
    }



    @PostConstruct
    public void testMapper() {
        List<Word> words = wordMapper.getWordsByBook("小学英语");
        System.out.println("Mapper 查询结果：" + words);
    }

    public List<String> getAllWordBooks() {
        return wordMapper.getAllWordBooks();
    }


}